<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2023/11/2
 * Time: 10:08
 */

namespace app\common\service;


use yii\helpers\ArrayHelper;
use yii\web\View;

class Tpl
{
    protected  $_tpl_path = "@app/common/tpl";

    const TPL = "@app/common/tpl";
    const PRODUCT = "@app/common/tpl_product";

    public function __construct($tpl = self::TPL)
    {
        $this->setTplPath($tpl);
    }

    /**
     * @return string
     */
    public  function getTplPath()
    {
        return $this->_tpl_path;
    }

    /**
     * @param $tpl_path
     * @return $this
     */
    public function setTplPath($tpl_path)
    {
        $this->_tpl_path = $tpl_path;
        return $this;
    }

    public function render($tpl, $data = [])
    {
        return (new View())->render($this->_tpl_path  . "/{$tpl}", $data);
    }
}